package util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnection {
    // 连接获取
    public static Connection getConnection() throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String sqlServer_url = "jdbc:mysql://localhost:3306/LibraryInformDB";
        String username = "root";
        String password = "root";
        return DriverManager.getConnection(sqlServer_url, username, password);
    }
    // 关闭连接
    public static void closeConnection(Connection connection) throws Exception {
        if (connection != null) {
            connection.close();
        }
    }
}